package com.wanyin.cloud.common.response;

import lombok.Data;

@Data
public class ResultVO<T> {
    private Integer code;
    private String msg;
    private T data;

    public ResultVO(Integer code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    /**
     * 返回成功消息
     *
     * @param data 数据对象
     * @return 成功消息
     */
    public static ResultVO success(Object data) {
        return new ResultVO(STATE.Success.getState(), STATE.Success.getMsg(), data);
    }

    public static ResultVO failed(String msg) {
        return new ResultVO(STATE.SystemErr.getState(), msg, null);
    }

    public static ResultVO error(STATE paramErr, String msg) {
        return new ResultVO(paramErr.getState(), msg, null);
    }

    public static ResultVO error(STATE paramErr) {
        return new ResultVO(paramErr.getState(), paramErr.getMsg(), null);
    }

    public static ResultVO error(String msg) {
        return new ResultVO(STATE.Error.getState(), msg, null);
    }

    public static ResultVO error() {
        return new ResultVO(STATE.Error.getState(), STATE.Error.getMsg(), null);
    }

}
